package com.gigalaxy.app.news.itemRenderers
{
	import flash.display.GradientType;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.DropShadowFilter;
	import flash.geom.Matrix;

	import spark.components.LabelItemRenderer;

	public class MainMenuItemRenderer extends LabelItemRenderer
	{
		private static var inited:Boolean=false;

		private static var labelShadow:DropShadowFilter;
		private static var colors:Array;
		private static var downColors:Array;
		private static var alphas:Array;
		private static var ratios:Array;
		private static var matrix:Matrix;

		public function MainMenuItemRenderer()
		{
			if (!inited)
			{
				labelShadow=new DropShadowFilter(1, 90, 0xFFFFFF, 1, 0, 0, 255);
				colors=[0xFFFFFF, 0xAEAEAE];
				downColors=[0xAEAEAE, 0xFFFFFF];
				alphas=[1, 1];
				ratios=[0, 255];
				matrix=new Matrix();

				inited=true;
			}

			super();
		}

		override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
		{
			if (down)
			{
				labelDisplay.setStyle("color", 0xCC0000);
			}
			else if (selected)
			{
				labelDisplay.setStyle("color", 0xCC0000);
			}
			else if (hovered)
			{
				labelDisplay.setStyle("color", 0xFFCC00);
			}
			else if (showsCaret)
			{
				labelDisplay.setStyle("color", 0xFFCC00);
			}
			else
			{
				labelDisplay.setStyle("color", 0x000000);
			}

			if (selected || down)
			{
				// gradient overlay
				matrix.createGradientBox(unscaledWidth, unscaledHeight, Math.PI / 2, 0, 0);
				graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
				graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
				graphics.endFill();
			}
			else
			{
				// gradient overlay
				matrix.createGradientBox(unscaledWidth, unscaledHeight, Math.PI / 2, 0, 0);
				graphics.beginGradientFill(GradientType.LINEAR, downColors, alphas, ratios, matrix);
				graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
				graphics.endFill();
			}

			drawBorder(unscaledWidth, unscaledHeight);
		}

		override protected function createLabelDisplay():void
		{
			super.createLabelDisplay();

			labelDisplay.setStyle("fontWeight", "bold");
			labelDisplay.filters=[labelShadow];
		}


		override protected function drawBorder(unscaledWidth:Number, unscaledHeight:Number):void
		{
			graphics.beginFill(0xFFFFFF);
			graphics.drawRect(0, 0, 1, unscaledHeight);
			graphics.endFill();

			graphics.beginFill(0xAAAAAA);
			graphics.drawRect(unscaledWidth - 1, 0, 1, unscaledHeight);
			graphics.endFill();

			if (selected || down)
			{
				graphics.beginFill(0xCC0000);
				graphics.drawRect(0, 0, unscaledWidth, 3);
				graphics.endFill();
			}

			graphics.beginFill(0xCC0000);
			graphics.drawRect(0, unscaledHeight - 3, unscaledWidth, 3);
			graphics.endFill();
		}
	}
}
